package cn.wzx.dao;

import cn.wzx.entity.BlogType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class BlogTypeDaoImpl implements BlogTypeDao {

    @Autowired
    MongoTemplate mongoTemplate;

    @Override
    public void add(BlogType blogType) {
        mongoTemplate.save(blogType);
    }

    @Override
    public List<BlogType> findAll() {
        return mongoTemplate.findAll(BlogType.class);
    }

    @Override
    public BlogType findById(String id) {
        Query query = new Query(Criteria.where("id").is(id));
        return mongoTemplate.findOne(query,BlogType.class);
    }
}
